package xyz.xtt.exchange.controller;

import com.github.xiaoymin.knife4j.core.util.Assert;
import jakarta.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.xtt.exchange.entity.TblAsset;
import xyz.xtt.exchange.service.impl.TblAssetServiceImpl;
import xyz.xtt.exchange.utils.ApiResult;

import java.util.List;

/**
 * This is Description
 * &#064;author  gzm
 * &#064;date  2024/10/23/
 */
@RequestMapping("/api/exchange")
@RestController
public class AssetController {
    @Autowired
    private TblAssetServiceImpl assetService;

    /**
     * 获取个人资产列表、支持条件查询
     * 一级分类：firstType
     * 二级分类：secondType
     */
    @GetMapping("/myAssets")
    public ApiResult<?> getMyAssets(@RequestParam(value = "firstType") String firstType
            , @RequestParam(value = "secondType", required = false) String secondType
            , @RequestParam(value = "state", required = false) Integer state
            , HttpServletRequest req) {
        String userId;
        try {
            userId = req.getHeader("userId");
            Assert.notBlank(userId, "非法参数");
        } catch (Exception e) {
            return ApiResult.failure(1, "illegal arguments");
        }
        return ApiResult.ok(assetService.getMyAssets(userId, state, firstType, secondType));
    }

    /**
     * 详情页
     *
     * @param goodsId
     * @param req
     * @param firstType
     * @param secondType 该参数只用在查询经营证
     * @return
     */
    @GetMapping("/getAssetDetails")
    public ApiResult<?> getAssetDetails(@RequestParam(value = "goodsId") String goodsId
            , @RequestParam(value = "firstType") String firstType
            , @RequestParam(value = "secondType") String secondType
            , HttpServletRequest req) {
        try {
            String userId = req.getHeader("uid");
           // Assert.notBlank(userId, "非法参数");
            Assert.notBlank(goodsId, "非法参数");
            Assert.notBlank(firstType, "非法参数");
        } catch (Exception e) {
            return ApiResult.failure(1, "illegal arguments");
        }
        return ApiResult.ok(assetService.getAssetDetails(goodsId, firstType, secondType));
    }
}

